package com.etc.service;

import com.etc.dao.CategorysDao;
import com.etc.dao.CinemasDao;
import com.etc.dao.ShowingsDao;
import com.etc.dao.TypesDao;
import com.etc.entity.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ShowingServiceImpl implements ShowingService {
    @Autowired
    ShowingsDao dao;
    @Autowired
    CinemasDao cinemasDao;
    @Autowired
    TypesDao typesDao;
    @Autowired
    CategorysDao categorysDao;

    @Override
    public Showings getShowSeat(int showNo) {
        Showings showings = dao.queryShowSeat(showNo);
        return showings;
    }

    @Override
    public List<Orders> getSellSeatByShowNo(int showNo) {
        return dao.querySellSeatByShowNo(showNo);
    }

    @Override
    public List<Showings> getShowingsByMovieAndDay(int movieNo, int day) {
        return dao.queryShowingsByMovieAndDay(movieNo, day);
    }

    @Override
    @Transactional
    public int doDelSeatByShwoingNo(int showNo) {
        return dao.delSeatByShwoingNo(showNo);
    }

    @Override
    public boolean addShowing(Showings showings) {
        int n = dao.addShowing(showings);
        return n > 0;
    }

    @Override
    public List<Cinemas> queryAllCin() {
        return cinemasDao.queryAll();
    }

    @Override
    public Integer querySeats(Integer cinema_no) {
        return cinemasDao.querySeats(cinema_no);
    }

    @Override
    public PageInfo<Showings> queryAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Showings> list = dao.queryAll();
        PageInfo<Showings> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<Types> queryAllType() {
        return typesDao.queryAll();
    }

    @Override
    public boolean addCinema(Cinemas cinemas) {
        int n = cinemasDao.addCinema(cinemas);
        return n > 0;
    }

    @Override
    public PageInfo<Cinemas> queryAllCint(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Cinemas> list = cinemasDao.queryAllCint();
        PageInfo<Cinemas> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public boolean addType(Types types) {
        int n = typesDao.addType(types);
        return n > 0;
    }

    @Override
    public List<Categorys> queryAllCate() {
        return categorysDao.queryAllCate();
    }

    @Override
    public boolean addCate(Categorys categorys) {
        int n = categorysDao.addCate(categorys);
        return n > 0;
    }

    @Override
    public boolean delShowing(Integer showing_no) {
        int n = dao.delShowing(showing_no);
        return n > 0;
    }

    @Override
    public boolean delCinema(Integer cinema_no) {
        int n = cinemasDao.delCinema(cinema_no);
        if (n > 0) {
            delByCinema(cinema_no);
        }
        return n > 0;
    }

    @Override
    public boolean delByCinema(Integer cinema_no) {
        int n = dao.delByCinema(cinema_no);
        return n > 0;
    }
}
